<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$user_id = get_loggedin_userid();

$value = get_input('value');
$reference = get_input('reference');

// verify first but store only hash
if(!validateReceipt($reference, FALSE) && !validateReceipt($reference, TRUE)) {
    echo json_encode(export_result(400, dt_export_coins($user_id)));
} else {

    $reference = md5($reference);

    if(dt_add_coins($user_id, $value, $reference)) {
        echo json_encode(export_result(200, dt_export_coins($user_id)));
    } else {
        echo json_encode(export_result(400, dt_export_coins($user_id)));
    }
}

?>
